Program asdf;
Type
	string_mas = array [1..100000] of string;
  variable_info = record
    name:string;
    vartype:string;
    var_sign:byte;
end;
Pmystruct = ^mystruct;

mystruct = record
    id:integer;
    name:string;
    from_line:integer;
    to_line:integer;
    list_of_variables: array[1..100000] of variable_info;
    nested_items: array[1..10000] of Pmystruct;
end;
VAR
  p:mystruct;
	words: string_mas;
	k,counter,i,n:integer;
	num_of_paswords:integer; {number of pascal words}
	oldwords:string_mas;
	paswords:string_mas;
	newwords:string_mas;
	myfuncs:string_mas;
	mynewfuncs:string_mas;
procedure writemas(var mas:string_mas;k:integer);
Var 
	i:integer;
begin
	for i:=1 to k do
	begin
		writeln('i=',i,' ',mas[i]);
	end;
end;
function isDelimeter(b:char):boolean;
var 
	i:integer;
	delimeters: array [1..16] of char;
Begin
	delimeters[1]:=',';
	delimeters[2]:=';';
	delimeters[3]:=':';
	delimeters[4]:=' ';
	delimeters[5]:='(';
	delimeters[6]:=')';
	delimeters[7]:='[';
	delimeters[8]:=']';
	delimeters[9]:='+';
	delimeters[10]:='-';
	delimeters[11]:='>';
	delimeters[12]:='<';
	delimeters[13]:='=';
	delimeters[14]:='=';
	delimeters[15]:='.';
	delimeters[16]:=#9;
	isdelimeter:=false;
	for i:=1 to 16 do
	begin
		if delimeters[i]=b then
		begin
	  		isdelimeter:=true;
	  		break;
	 	end;
	end;
end;
Procedure SkipDelimiters(Var i:integer;str:string);
Begin
    while (i<=length(str)) and (isDelimeter(str[i]))=true do
			begin
				i:=i+1;        
			end;
End;
Procedure savewords(str:string;var maswords:string_mas;Var i:integer;Var counter:integer);
Var wordflag:integer;
Begin
   wordflag:=0;
   while (i<=length(str)) and (isDelimeter(str[i])=false) and (str[i]<>'{') and (str[i]<>'}') do
        begin
    		wordflag:=1;
			maswords[counter]+=str[i];
			i:=i+1;
			if (i>length(str)) then
				break;           
		end;
	if wordflag = 1 then
		begin
			counter:=counter+1;
			wordflag:=0;
		end;
end;
Function comparestr(str1,str2:string):boolean;
Var i,flag:integer;
Begin
    flag:=0;
    If length(str1)=length(str2) then
    Begin
        For i:=1 to length(str1) do
        Begin
            If Upcase(str1[i])=Upcase(str2[i]) then
            inc(flag);
        end;
    end;
    If flag=length(str1) then 
        comparestr:=true
    else
        comparestr:=false;
End;
Function compare(mas1:string_mas;mas2:string_mas;Var mas3:string_mas;counter:integer;counter1:integer):integer;
Var k,i,keyword,l,j:integer;
Begin
k:=0;
For i:=1 to counter do
	begin
	keyword:=0;
 	  For j:=1 to counter1 do
 	  begin
		    if comparestr(mas1[i],mas2[j])=true then
		    begin
		        keyword:=1;
		        break;
		    end;
      end;
      If keyword=0 then
    	begin
     		k:=k+1;
    		mas3[k]:=mas1[i];
    	end;
 	end;
 compare:=k;
End;
Procedure readsave(fname:string; var mas:string_mas;var counter:integer);
Var i,flag,flag1:integer;
    str,str1:string;
    fil:text;
Begin
	assign(fil,fname);
	reset(fil);
	while not eof(fil) do
	begin
		readln(fil,str);
		i:=1;
		flag:=0;
		flag1:=0;
		while i<=length(str) do
		begin			
			SkipDelimiters(i,str);
			if i>length(str) then
				break;
			if str[i] = '''' then
			begin
			    flag1:=1-flag1;
			end;
			if str[i] = '{' then flag:=1;
			if str[i] = '}' then flag:=0;
			if (flag=1) or (flag1=1) or (str[i] = '}') or (str[i] = '''') then
			begin
			    inc(i);
			    continue;
		    end;
            savewords(str,mas,i,counter);
		end;
	end;
	close(fil);
End;
Procedure dublicates (VAr mas:string_mas;counter:integer);
Var
i,j:integer;
str:string;
Begin
i:=0;
j:=0;
str:=mas[1];
While i<>counter+1 do
    begin
    For j:=2 to counter do
        begin
        If i=j then break;
        If str=mas[j] then mas[j]:=' ';
        end;
    inc(i);
    str:=mas[i];
    end;
end;
Function skipstring (Var mas:string_mas;counter:integer):integer;
Var
i,k,j,flag:integer;
begin
k:=counter;
j:=1;
For i:=1 to k do
    Begin
    If mas[i]<>' ' then flag:=1 else flag:=0;
    If flag=1 then 
        begin
        mas[j]:=mas[i];
        inc(j);
        end;
    flag:=0;
    End;
skipstring:=j;
end;
Procedure filtmas(Var mas:string_mas;k:integer);
Var
i,j,flag:integer;
str:string;
Begin
For i:=1 to k do
    Begin
    For j:=1 to length(mas[i]) do
        begin
        str:=mas[i];
        if (ord(str[j])>=48) and (ord(str[j])<=57)  then else flag:=1;
        end;
    If flag<>1 then mas[i]:=' ';
    flag:=0;
    End;
End;
Function funcnames (Var funcs:string_mas;mas:string_mas;k:integer):integer;
Var
i,j:integer;
str1,str2:string;
Begin
j:=1;
str1:='function';
str2:='procedure';
For i:=1 to k do 
    begin
    If (comparestr(mas[i],str1)=true) or (comparestr(mas[i],str2)=true) then 
        begin
        funcs[j]:=mas[i+1];
        inc(j);
        end;
    end;
dec(j);
funcnames:=j;
end;
Function func (Var newfuncs:string_mas;mas:string_mas;newmas:string_mas;k:integer;n:integer):integer;
Var
i,j,l,flag,m:integer;
str1,str2,str3,str4:string;
Begin
str1:='function';
str2:='procedure';
str3:='begin';
str4:='end';
flag:=0;
For i:=1 to k do
  Begin
    For j:=1 to n do
      begin
      If (comparestr(mas[i],str1)=true) or (comparestr(mas[i],str2)=true) then flag:=1;
      If flag=1 then 
        begin
        m:=i;
        While flag<>0 do
          begin
          If (comparestr(mas[m],str3)=true) then inc(flag);
          inc(m);
          end;
        While flag<>0 do
          begin
          If (comparestr(mas[m],mas[j])=true) then 
            begin
            myfuncs[l]:=mas[m]+'->'+mas[j];
            inc(l);
            end;
          IF (comparestr(mas[m],str4)=true) then dec(flag);
          If (comparestr(mas[m],str3)=true) then inc(flag);
          inc(m);
          end;
        end;
      end;
  end;
func:=l;
end;
Begin
	k:=1;
	counter:=1;
	readsave('NEWPR1.PAS',words,counter);
	num_of_paswords:=1;
	readsave('paswords.txt',paswords,num_of_paswords);
	dec(num_of_paswords);
	k:=0;
	counter:=counter-1;
	k:=counter;
	{writemas(words,counter);}
 	{k:=compare(words,paswords,newwords,counter,num_of_paswords);}
	{writemas(newwords,k);}
	{dublicates(newwords,k);}
	{k:=skipstring(newwords,k);}
	For i:=1 to k do
	  begin
	  If Compare(words[i-1],'program')=true then
	    begin
	    p.id:=0;
	    If compare(words[i-1],'Var')=true then
	      begin
	      k:=i;
	      while (compare(words[k],'begin')=false) or (compare(words[k],'function')=false) or (compare(words[k],'procedure')=false)
	          p.name:=words[i];
	      end;
	    end;
	  end;
	{filtmas(newwords,counter);
	k:=skipstring(newwords,counter);
  n:=funcnames(myfuncs,newwords,k);
	writemas(myfuncs,n);}
end.